package Service;

import Entity.File;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import dao.FileDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FileServiceImpl extends ServiceImpl<FileDao, File> implements FileService {
    @Autowired
    private FileDao fileDao;


    @Override
    public Boolean saveFile ( File file ) {
        return fileDao.insert ( file ) > 0;
    }

    @Override
    public Boolean modify ( File file ) {
        return fileDao.updateById ( file ) > 0;
    }

    public Boolean deleteById ( Integer id ) {
        return fileDao.deleteById ( id ) > 0;
    }

    public File getFileById ( Integer id ) {
        return fileDao.selectById ( id );
    }

    @Override
    public List<File> getAllFileByUserId ( Integer userId ) {
        Map<String, Object> map = new HashMap<> ();
        map.put ( "belongs" , userId );
        return fileDao.selectByMap ( map );
    }

    public List<File> getAllFile ( ) {
        return fileDao.selectList ( null );
    }


}
